/*H-ui.js v1.5.1 date:15:42 2014-9-30 by:guojunhui*/
/*$().resize()*/
(function($,h,c){var a=$([]),e=$.resize=$.extend($.resize,{}),i,k="setTimeout",j="resize",d=j+"-special-event",b="delay",f="throttleWindow";e[b]=250;e[f]=true;$.event.special[j]={setup:function(){if(!e[f]&&this[k]){return false}var l=$(this);a=a.add(l);$.data(this,d,{w:l.width(),h:l.height()});if(a.length===1){g()}},teardown:function(){if(!e[f]&&this[k]){return false}var l=$(this);a=a.not(l);l.removeData(d);if(!a.length){clearTimeout(i)}},add:function(l){if(!e[f]&&this[k]){return false}var n;function m(s,o,p){var q=$(this),r=$.data(this,d);r.w=o!==c?o:q.width();r.h=p!==c?p:q.height();n.apply(this,arguments)}if($.isFunction(l)){n=l;return m}else{n=l.handler;l.handler=m}}};function g(){i=h[k](function(){a.each(function(){var n=$(this),m=n.width(),l=n.height(),o=$.data(this,d);if(m!==o.w||l!==o.h){n.trigger(j,[o.w=m,o.h=l])}});g()},e[b])}})(jQuery,this);

if (navigator.userAgent.match(/IEMobile\/10\.0/)) {
  var msViewportStyle = document.createElement("style")
  msViewportStyle.appendChild(
    document.createTextNode(
      "@-ms-viewport{width:auto!important}"
    )
  )
  document.getElementsByTagName("head")[0].appendChild(msViewportStyle)
}

function trim(str){ //删除左右两端的空格
	return str.replace(/(^\s*)|(\s*$)/g, "");
}
function ltrim(str){ //删除左边的空格
　　return str.replace(/(^\s*)/g,"");
}
function rtrim(str){ //删除右边的空格
　　return str.replace(/(\s*$)/g,"");
}
/*添加收藏
<a title="收藏本站" href="javascript:addFavoritepage(0);">收藏本站</a>
*/
var webName ="H-ui前端框架";
var webSite ="http://www.h-ui.net/";
/*收藏主站*/
function addFavorite(){try{window.external.addFavorite(webSite,webName);}catch(e){try{window.sidebar.addPanel(webName,webSite,"");}catch(e){alert("加入收藏失败，请使用Ctrl+D进行添加");}}}
/*收藏页面
<a title="收藏本页" href="javascript:addFavoritepage(0);">收藏本页</a>
*/
function addFavoritepage(){var sURL=window.location.href;var sTitle=document.title;try{window.external.addFavorite(sURL,sTitle);}catch(e){try{window.sidebar.addPanel(sTitle,sURL,"");}catch(e){alert("加入收藏失败，请使用Ctrl+D进行添加");}}}
/*设为首页*/
function setHome(obj){
  try{obj.style.behavior="url(#default#homepage)";obj.setHomePage(webSite);}
  catch(e){if(window.netscape){
	  try {netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");}
	  catch(e){alert("此操作被浏览器拒绝！\n请在浏览器地址栏输入\"about:config\"并回车\n然后将 [signed.applets.codebase_principal_support]的值设置为'true',双击即可。");}
	  var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
	  prefs.setCharPref('browser.startup.homepage',url);}}
}

/*iframe 自适应宽高*/
/*<iframe src ="" frameborder="0" marginheight="0" marginwidth="0" frameborder="0" scrolling="auto" id="id" name="ifm" onload="javascript:iframesize('id');" width="100%"></iframe>*/
function iframesize(obj) {
	var pTar = null;
	if (document.getElementById){
		pTar = document.getElementById(obj);
	}
	else{
		eval('pTar = ' + obj + ';');
	}
	if (pTar && !window.opera){
		/*begin resizing iframe */
		pTar.style.display="block";
		if (pTar.contentDocument && pTar.contentDocument.body.offsetHeight){
			/*ns6 syntax*/
			pTar.height = pTar.contentDocument.body.offsetHeight +20;
			pTar.width = pTar.contentDocument.body.scrollWidth+20;
		}
		else if (pTar.Document && pTar.Document.body.scrollHeight){
			/*ie5+ syntax*/
			pTar.height = pTar.Document.body.scrollHeight;
			pTar.width = pTar.Document.body.scrollWidth;
		}
	}
}

/*隐藏显示密码*/
(function ( $ ) {
    $.fn.togglePassword = function( options ) {
        var s = $.extend( $.fn.togglePassword.defaults, options ),
        input = $( this );

        $( s.el ).bind( s.ev, function() {
            "password" == $( input ).attr( "type" ) ?
                $( input ).attr( "type", "text" ) :
                $( input ).attr( "type", "password" );
        });
    };

    $.fn.togglePassword.defaults = {
        ev: "click"
    };
}( jQuery ));

/*Huimodalalert*/
function Huimodal_alert(info,speed){
	$(document.body).append(
	'<div id="modal-alert" class="modal hide modal-alert">'+
	  '<div class="modal-alert-info">'+info+'</div>'+
	'</div>'
	);
	$("#modal-alert").fadeIn();
	
	setTimeout("Huimodal_alert_hide()",speed);
}
function Huimodal_alert_hide() {
	$("#modal-alert").fadeOut("normal",function(){
		$("#modal-alert").remove();
	});
}

/*jQuery脚本*/
$(function(){	
	/*hover*/
	jQuery.Huihover =function(obj) {
		$(obj).hover(function(){$(this).addClass("hover");},function(){$(this).removeClass("hover");});
	};
	
	/*****表单*****/
	/*表单得到失去焦点*/
	jQuery.Huifocusblur = function(obj) {
        $(obj).focus(function() {$(this).addClass("focus").removeClass("inputError");});
        $(obj).blur(function() {$(this).removeClass("focus");});
    };
    $.Huifocusblur(".input-text,.textarea");
	
	/*按钮loading*/
	$('.btn-loading').click(function () {
		var $btn = $(this);
		var btnval = $btn.val();
		$btn.addClass("disabled").val("loading").attr("disabled","disabled");
		setTimeout(function(){
			$btn.removeClass("disabled").val(btnval).removeAttr("disabled");
		}, 3000);
	});	
	
	/*模拟下拉菜单*/
	jQuery.Huiselect = function(divselectid,inputselectid) {
		var inputselect = $(inputselectid);
		$(divselectid+" cite").click(function(){
			var ul = $(divselectid+" ul");
			ul.slideToggle();
		});
		$(divselectid+" ul li a").click(function(){
			var txt = $(this).text();
			$(divselectid+" cite").html(txt);
			var value = $(this).attr("selectid");
			inputselect.val(value);
			$(divselectid+" ul").hide();
		});
		$(document).click(function(){$(divselectid+" ul").hide();});
	};
	$.Huiselect("#divselect","#inputselect");
	
	/*全选*/
	$("table thead th input:checkbox").on("click" , function(){
    	var that = this;
    	$(this).closest("table").find("tr > td:first-child input:checkbox").each(function(){
    		this.checked = that.checked;
    		$(this).closest("tr").toggleClass("selected");
    	});
    });
	
	
    /*上传*/
    $(document).on("change",".input-file",function(){
		var uploadVal=$(this).val();
		$(this).parent().find(".upload-url").val(uploadVal);
	});
	
	/*左侧菜单*/	
	$(".menu_dropdown dl dt").click(function(){if($(this).parent("dl").hasClass('selected')){$(this).parent("dl").removeClass('selected');}else{$(this).parent("dl").addClass("selected");}});
	/*文本框*/
	$(".placeholder").click(function(){$(this).hide();$(this).parents("p").find(".input-text").focus();});
	/*得到焦点*/
	function inputfocus(obj){if($(obj).val()==""){$(obj).parent().find(".placeholder").hide();}}
	/*失去焦点*/
	function inputblur(obj){if($(obj).val()==""){$(obj).parent().find(".placeholder").show();}}

	
		
	
	/*资讯详情页 字号变化*/
	$("#fontbig").click(function(){$("#fontSmall").css("color","#0B3B8C");$(this).css("color","#666");$("#cnt_main_article").css("font-size","18px");});
	$("#fontSmall").click(function(){$("#fontbig").css("color","#0B3B8C");$(this).css("color","#666");$("#cnt_main_article").css("font-size","14px");});

	/*顶部展开定时自动关闭广告*/ 
	$("#banner").slideDown("slow");
	
	/*图片预览*/
	$("a.preview").hover(
		function(){
			$(this).addClass("active");
			$("#tooltip-preview").remove();
			var winW=$(window).width();
			var winW5=winW/2;
			this.myTitle = this.title;
			this.title = "";
			var midimg = $(this).attr('data-preview');
			if(midimg ==''){return false;}
			else{
				var imgT=$(this).parents(".imgItem").offset().top;
				var imgL=$(this).parents(".imgItem").offset().left;	
				var imgW=$(this).parents(".imgItem").width();
				var imgH=$(this).parents(".imgItem").height();
				var ww=(imgL+imgW/2);
				if(ww < winW5){
					var tooltipLeft=(imgW+imgL)+"px";	
				}
				else{
					var tooltipRight=(winW-imgL)+"px";
				}
				var tooltip_keleyi_com = "<div id='tooltip-preview' style='top:"+ imgT +"px;right:"+ tooltipRight +";left:"+ tooltipLeft +"'><span id='tooltip-keleyi-div' class='loading' style='width:50px; height:50px'></span></div>";
				$("body").append(tooltip_keleyi_com);
				var midimgW = $(this).attr('data-width');
				var midimgH = $(this).attr('data-height');
				var imgTitle = this.myTitle ? "<br />" + this.myTitle + " 产品预览图" : "";
				/*图片预加载*/
				var image = new Image();/*创建一个Image对象*/
				image.onload = function () {
					if($('a.preview.active').attr('data-preview') == midimg){
						var midingW2 = this.width;
						var midingH2 = this.height;
						$("#tooltip-keleyi-div").css({"width":midingW2+"px","height":midingH2+"px"});
						$('#tooltip-keleyi-div').append(this);	
					}
				};
				image.src = midimg;
			}
		},
		function(){
			$(this).removeClass("active");
			this.title = this.myTitle;
			$("#tooltip-preview").remove();
		}
	);
	
	/*Huialert*/
	$.Huihover('.Huialert .icon-remove');
	$(".Huialert .icon-remove").on("click",function(){
		var Huialert = $(this).parents(".Huialert");
		Huialert.fadeOut("normal",function(){
		  Huialert.remove();
		});
	});

	
});

function displayimg(){
	$("#banner").slideUp(1000,function(){
		$("#top").slideDown(1000);
	});
}
setTimeout("displayimg()",4000);

/*让浏览器支持input type=number */
/*jQuery.fn.numbertype = function(){
	var numberFlag = null,
	timeInterval = 180,
	isKeyPress = false,
	changeAction = function(step, numberText){
		var value = numberText.value,
		maxNum = jQuery(numberText).attr('max') * 1,
		minNum = jQuery(numberText).attr('min') * 1,
		result = 0;
		if(value === "" || !/^\d+$/.test(value)){
			value = 0;
		}
		result = value * 1 + step;
		if((step < 0 && result < minNum) || (step > 0 && result > maxNum)){
			clearTimeout(numberFlag);
			return;
		}
		numberText.value = result;
		if(timeInterval <= 10){
			timeInterval = 10;
		}else{
			timeInterval -= 10;
		}
		numberFlag = setTimeout(function(){changeAction(step, numberText)}, timeInterval);
	},
	upAction = function(numberText, currentObj){
		var step = jQuery(numberText).attr('step');
		if(step === undefined || !/^\d+$/.test(step)){
			step = 1;
		}
		step *= 1;
		if(currentObj !== undefined){
			jQuery(currentObj).addClass('ncb_btn_selected');
		}
		timeInterval = 180;
		changeAction(step, numberText);
	},
	downAction = function(numberText, currentObj){
		var step = jQuery(numberText).attr('step');
		if(step === undefined || !/^\d+$/.test(step)){
			step = 1;
		}
		step *= -1;
		if(currentObj !== undefined){
			jQuery(currentObj).addClass('ncb_btn_selected');
		}
		timeInterval = 180;
		changeAction(step, numberText);
	},
	construct = function(height, numberText){
		var numberControlBox = document.createElement('span'),
		upBtn = document.createElement('span'),
		ico_up = document.createElement('span'),
		ico_down = document.createElement('span'),
		downBtn = document.createElement('span');
		numberControlBox.className = "numberControlBox";
		numberControlBox.style.height = height + "px";
		upBtn.className = "ncb_up";
		upBtn.style.height = Math.floor(height/2 - 3) + "px";
		downBtn.className = "ncb_down";
		downBtn.style.height = Math.floor(height/2 - 3) + "px";
		ico_up.className = "ncb_ico";
		ico_down.className = "ncb_ico";
		ico_up.style.height = Math.floor(height/2 - 3) + "px";
		ico_down.style.height = Math.floor(height/2 - 3) + "px";
		upBtn.appendChild(ico_up);
		downBtn.appendChild(ico_down);
		numberControlBox.appendChild(upBtn);
		numberControlBox.appendChild(downBtn);
		jQuery(upBtn).mousedown(function(){
			upAction(numberText, this);
			}).mouseenter(function(){jQuery(this).addClass('ncb_btn_hover');
			}).mouseleave(function(){jQuery(this).removeClass('ncb_btn_hover');
			clearTimeout(numberFlag);
		}).mouseup(function(){
			jQuery(this).removeClass('ncb_btn_selected');
			clearTimeout(numberFlag);
		});
		jQuery(downBtn).mousedown(function(){
			downAction(numberText, this);
		}).mouseenter(function(){
			jQuery(this).addClass('ncb_btn_hover');
		}).mouseleave(function(){
			jQuery(this).removeClass('ncb_btn_hover');
			clearTimeout(numberFlag);
		}).mouseup(function(){
			jQuery(this).removeClass('ncb_btn_selected');
		clearTimeout(numberFlag);
	});
	jQuery(numberText).keydown(function(event){
		var keycode = event.keyCode;
		if(isKeyPress){
			return false;
		}
		if(keycode === 38){
			upAction(numberText);
		}else if(keycode === 40){
			downAction(numberText);
		}
		isKeyPress = true;
	}).keyup(function(){
		clearTimeout(numberFlag);
		isKeyPress = false;
	});
	return numberControlBox;
};
this.each(function(index){
	var numberText = jQuery(this);
	jQuery(construct(numberText.outerHeight(), this)).insertAfter(numberText);
});
jQuery(document).mouseup(function(){
	jQuery('.ncb_up').removeClass('ncb_btn_selected');
	jQuery('.ncb_down').removeClass('ncb_btn_selected');
});
return this;
};
(function(){
	if(!Modernizr.inputtypes.number){
		jQuery('input[type=number]').numbertype();
	}
})();*/